package com.yuyuan.user.controller;


import cn.hutool.core.bean.BeanUtil;
import com.yuyuan.api.domain.IconDTOC;
import com.yuyuan.api.domain.UserDTOC;
import com.yuyuan.common.domain.Issue;
import com.yuyuan.common.domain.Result;
import com.yuyuan.user.domain.po.User;
import com.yuyuan.user.mapper.UserMapper;
import com.yuyuan.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @Autowired
    private UserMapper userMapper;

    @PostMapping("/login/wechat")
    public Result WXLogin(@RequestParam(value = "code", required = false) String code, @RequestParam String userName) {
        return userService.WXLogin(code,userName);
    }
    @PostMapping("/logout/wechat")
    public Result logOut(@RequestParam String authorization){
        return userService.logOut(authorization);
    }

    @GetMapping("/of/me")
    public Result getMe(){
        return userService.getMe();
    }

    @GetMapping("/of/{userId}")
    public Result getOther(@PathVariable Long userId){
        return userService.getOther(userId);
    }

    @PostMapping("/issue")
    public Result sendIssue(@RequestBody Issue issue){
        return userService.sendIssue(issue);
    }

    // client
    @GetMapping("/client/selectById/{userId}")
    public UserDTOC selectById(@PathVariable Long userId){
        User user = userMapper.selectById(userId);
        return BeanUtil.copyProperties(user, UserDTOC.class);
    }

    @PutMapping("/client/updateIcon")
    public Result updateIcon(@RequestBody IconDTOC iconDTOC){
        return userService.updateIcon(iconDTOC);
    }

    @PutMapping("/client/addFollowee/{userId}")
    public void addFollowee(@PathVariable Long userId){
        userMapper.addFollowee(userId);
    }

    @PutMapping("/client/addFans/{userId}")
    public void addFans(@PathVariable Long userId){
        userMapper.addFans(userId);
    }

    @PutMapping("/client/subFollowee/{userId}")
    public void subFollowee(@PathVariable Long userId){
        userMapper.subFollowee(userId);
    }

    @PutMapping("/client/subFans/{userId}")
    public void subFans(@PathVariable Long userId){
        userMapper.subFans(userId);
    }


}
